package com.lp.biz.operations.controller;

import com.lp.biz.operations.model.vo.TodayAdd;
import com.lp.biz.operations.service.BizRecommendTodayService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.entity.PageParams;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.TODAY;

/**
 * BizRecommendTodayController
 * @program: backend
 * @author Ke.Song
 * @since 2024-07-14 23:26:00
 */
@RestController
@RequestMapping("/today")
public class BizRecommendTodayController {

    @Autowired
    private BizRecommendTodayService todayService;

    /**
     * 获取今日推荐位列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("")
    @PermissionAnnotation(menus = {TODAY})
    public CommonResult getTodayList(PageParams query) {
        return todayService.getTodayList(query);
    }

    /**
     * 创建/更新今日推荐
     * @param params 推荐参数
     * @return 处理结果
     */
    @PostMapping("")
    @PermissionAnnotation(menus = {TODAY})
    public CommonResult addOrUpdateToday(@RequestBody@Validated TodayAdd params) {
        todayService.addOrUpdateToday(params);
        return CommonResult.success();
    }

    /**
     * 删除今日推荐
     * @param recommendId 推荐id
     * @return 处理结果
     */
    @DeleteMapping("/{recommendId}")
    @PermissionAnnotation(menus = {TODAY})
    public CommonResult deleteTodayRecommend(@PathVariable Integer recommendId) {
        todayService.deleteTodayRecommend(recommendId);
        return CommonResult.success();
    }
}
